package ${package.Controller};

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.web.bind.annotation.*;
import org.springframework.beans.factory.annotation.Autowired;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import ${package.Entity}.${entity};
import ${package.Service}.${table.serviceName};
import java.util.Date;
import com.generator.utils.*;
<#if restControllerStyle>import org.springframework.web.bind.annotation.RestController;
<#else>import org.springframework.stereotype.Controller;
</#if>
<#if superControllerClassPackage??>import ${superControllerClassPackage};</#if>

/**
* ${table.comment!} 前端控制器
*
* @author ${author}
* @since ${date}
*/
@Api(tags = "${entity}API")
<#if restControllerStyle>
    @RestController
<#else>
    @Controller
</#if>
@RequestMapping("<#if entity??>/${entity}</#if>")
<#if kotlin>
    class ${table.controllerName}<#if superControllerClass??> : ${superControllerClass}()</#if>
<#else>
    <#if superControllerClass??>
        public class ${table.controllerName} extends ${superControllerClass} {
    <#else>
        public class ${table.controllerName} {
    </#if>
    @Autowired
    private ${table.serviceName} service;

    @ApiOperation(value = "分页列表")
    @ApiImplicitParams({
    @ApiImplicitParam(name = "currentPage",value = "当前页码",paramType = "query",dataType = "int"),
    @ApiImplicitParam(name = "pageSize",value = "每页显示个数",paramType = "query",dataType = "int")
    })
    @PostMapping(value = "/page")
    public Result page(@RequestBody ${entity} entity,@RequestParam Integer currentPage,@RequestParam Integer pageSize){

    Page<${entity}> page = new Page<>(currentPage,pageSize);
    QueryWrapper<${entity}> queryWrapper = new QueryWrapper();
    //分页查看列表
    IPage<${entity}> pageInfo = service.selectPage(page,queryWrapper);
    //返回结果集
    return new Result().ok(new PageData<>(pageInfo.getRecords(),pageInfo.getTotal()));
    }

    /**
    * 添加信息
    */
    @PostMapping("add")
    @ApiOperation("添加信息")
    public Result add(@RequestBody ${entity} entity){
    int n = service.add(entity);
    if(n>0){
    return new Result();
    }else{
    return new Result().err(400,"添加失败");
    }
    }

    /**
    * 编辑信息
    */
    @PostMapping("update")
    @ApiOperation("修改信息")
    public Result update(@RequestBody ${entity} entity){
    int n = service.update(entity);
    if(n>0){
    return new Result();
    }else{
    return new Result().err(400,"编辑失败");
    }
    }


    /**
    * 根据ids删除信息
    */
    @PostMapping("del")
    @ApiOperation("根据ids删除信息")
    public Result del(@RequestBody Integer[] ids){
    int n = service.deleteBatchIds(ids);
    if(n>0){
    return new Result();
    }else{
    return new Result().err(400,"删除失败");
    }
    }
    }
</#if>